#include<stdio.h>
#include<stdlib.h>

int digit_sum(int N){
	int sum=0,s = N;
	while(s){
		sum += s%10;
		s /= 10;
	}
	return sum;
}

int is_simith(int tnum){
	int i,num = tnum,sum=0;
	for(i=2;i*i<=num;i++){
		while(num%i==0){
			sum += digit_sum(i);
			num /= i;
		}
	}
	if(tnum == num)
	    return 0;
	if(num != 1)
	    sum += digit_sum(num);
	return digit_sum(tnum) == sum;
}

int main(){
	int N,i;
	while(scanf("%d",&N),N){
		for(i=N+1;;i++){
			if(is_simith(i)){
            	printf("%d\n",i);
			    break;
			}
		}
	}
	return 0;
}
